package edu.njfu.intentdemo

import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import edu.njfu.intentdemo.util.CommonUtil

class WebViewDemo : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_web_view_demo)
        val button6 = findViewById<Button>(R.id.button6);
        button6.setOnClickListener {
            //打开网页
            var url: Uri = Uri.parse("http://www.baidu.com")
            val webView = Intent(Intent.ACTION_VIEW, url)
            startActivity(webView)
        }

        val button7 = findViewById<Button>(R.id.button7);
        button7.setOnClickListener {
            //打开拨号
            var url: Uri = Uri.parse("tel:10086")
            val webView = Intent(Intent.ACTION_VIEW, url)
            startActivity(webView)
        }

        val button8 = findViewById<Button>(R.id.button8);
        button8.setOnClickListener {
            //打开地图
            var url: Uri = Uri.parse("geo:39.899533,116.036476")
            val webView = Intent(Intent.ACTION_VIEW, url)
            startActivity(webView)
        }

        val button9 = findViewById<Button>(R.id.button9);
        button9.setOnClickListener {
            //打开短信
            val uri=Uri.parse("smsto:10086")
            val intent = Intent(Intent.ACTION_SENDTO,uri);
             intent.putExtra("sms_body","亲爱的同学们，你们好！")
            startActivity(intent)
        }

        val button10 = findViewById<Button>(R.id.button10);
        button10.setOnClickListener {
            //发送邮件
            val uri=Uri.parse("mailto:1724226325@qq.com")
            val intent = Intent(Intent.ACTION_SENDTO,uri);
            intent.putExtra(Intent.EXTRA_SUBJECT,"交作业了！")
            intent.putExtra(Intent.EXTRA_TEXT,"Please submit your homework to me!")
            startActivity(intent)
        }

        val button11 = findViewById<Button>(R.id.button11);
        button11.setOnClickListener {
            //播放视频
            val uri=Uri.parse("content:///sdcard/Movies/video1.mp4")
            val intent = Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(uri,"video/mp4")
            CommonUtil.equestPermissions(this)
            startActivity(intent)
        }
    }
}